package constants

import (
	"go_gvm_mini/instructions/base"
	"go_gvm_mini/rtda"
)

// 从操作数中获取一个byte型整数,扩张成int类型,然后推入栈顶
type BIPUSH struct {
	val int8
}

func (self *BIPUSH) FetchOperands(byteCodeReader *base.ByteCodeReader) {
	self.val = byteCodeReader.ReadInt8()
}

func (self *BIPUSH) Execute(frame *rtda.JFrame) {
	i := int32(self.val)
	frame.OperandStack().PushInt(i)
}

type SIPUSH struct {
	val int16
}

func (self *SIPUSH) FetchOperands(byteCodeReader *base.ByteCodeReader) {
	self.val = byteCodeReader.ReadInt16()
}

func (self *SIPUSH) Execute(frame *rtda.JFrame) {
	i := int32(self.val)
	frame.OperandStack().PushInt(i)
}
